CC = g++
CFLAGS = -O3 -g -I$(HOME)/include -lpthread

ALL = bitmatrices.h    \
		  bitmatrices.cpp  \
		  reed_sol.h       \
		  reed_sol.cpp     \
		  jerasure.h       \
		  jer_matrix.cpp   \
		  galois.h         \
		  galois.cpp       \
		  jer_gen_t.cpp    \
		  jer_slices.cpp   \
		  baseline_performance \
			encoder		   \
			mt_encode \
		  decoder 

all: $(ALL)

clean:
	rm -f core *.o $(ALL) a.out

.SUFFIXES: .cpp .o
.cpp.o:
	$(CC) $(CFLAGS) -c $*.cpp

bitmatrices.h: ../bitmatrices.h
	rm -f bitmatrices.h ; cp ../bitmatrices.h . ; chmod 0444 bitmatrices.h

bitmatrices.cpp: ../bitmatrices.cpp
	rm -f bitmatrices.cpp ; cp ../bitmatrices.cpp . ; chmod 0444 bitmatrices.cpp

reed_sol.h: ../reed_sol.h
	rm -f reed_sol.h ; cp ../reed_sol.h . ; chmod 0444 reed_sol.h

reed_sol.cpp: ../reed_sol.cpp
	rm -f reed_sol.cpp ; cp ../reed_sol.cpp . ; chmod 0444 reed_sol.cpp

jerasure.h: ../jerasure.h
	rm -f jerasure.h ; cp ../jerasure.h . ; chmod 0444 jerasure.h

jer_matrix.cpp: ../jer_matrix.cpp
	rm -f jer_matrix.cpp ; cp ../jer_matrix.cpp . ; chmod 0444 jer_matrix.cpp

galois.h: ../galois.h
	rm -f galois.h ; cp ../galois.h . ; chmod 0444 galois.h

galois.cpp: ../galois.cpp
	rm -f galois.cpp ; cp ../galois.cpp . ; chmod 0444 galois.cpp

jer_gen_t.cpp: ../jer_gen_t.cpp
	rm -f jer_gen_t.cpp ; cp ../jer_gen_t.cpp . ; chmod 0444 jer_gen_t.cpp

jer_slices.cpp: ../jer_slices.cpp
	rm -f jer_slices.cpp ; cp ../jer_slices.cpp . ; chmod 0444 jer_slices.cpp

galois.o: galois.h
jer_gen_t.o: jerasure.h galois.h
jer_slices.o: jerasure.h galois.h
jer_matrix.o: jerasure.h galois.h
bitmatrices.o: jerasure.h galois.h bitmatrices.h
reed_sol.o: jerasure.h galois.h reed_sol.h

mt_encode: reed_sol.o galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o mt_encode.o
	$(CC) $(CFLAGS) -o mt_encode galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o mt_encode.o reed_sol.o

encoder: reed_sol.o galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o encoder.o
	$(CC) $(CFLAGS) -o encoder galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o encoder.o reed_sol.o

decoder: reed_sol.o galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o decoder.o
	$(CC) $(CFLAGS) -o decoder galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o decoder.o reed_sol.o

baseline_performance: reed_sol.o galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o baseline_performance.o
	$(CC) $(CFLAGS) -o baseline_performance galois.o jer_matrix.o jer_gen_t.o jer_slices.o bitmatrices.o baseline_performance.o reed_sol.o
